﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infra.Entity;


namespace Infra.Common.DAO
{
   public class ROLEDAL
    {


        public static void Salvar(SEGROLE Role)
        {
            using (DBInfraEntityDataContext dc = new DBInfraEntityDataContext())
            {
                if (Role.CODROLE != 0)
                {
                    //Alterar o tipo de produto
                    var RL = dc.SEGROLEs.Single(R => R.CODROLE == Role.CODROLE);
                    RL.CODUSER = Role.CODUSER;
                    RL.CODGROUP = Role.CODGROUP;
          
                    dc.SubmitChanges();
                }
                else
                {
                    //Salvar o tipo de produto
                    dc.SEGROLEs.InsertOnSubmit(Role);
                    dc.SubmitChanges();
                }
            }
        }


        public static void Excluir(int idROLE)
        {
            using (DBInfraEntityDataContext dc = new DBInfraEntityDataContext())
            {
                var RL = dc.SEGROLEs.Single(R => R.CODROLE == idROLE);
                dc.SEGROLEs.DeleteOnSubmit(RL);
                dc.SubmitChanges();
            }
        }



        public static List<SEGROLE> Pesquisar(int codigo)
        {
            List<SEGROLE> listaRole = null;

            using (DBInfraEntityDataContext dc = new DBInfraEntityDataContext())
            {
                var RL = from R in dc.SEGROLEs
                         where ((codigo.Equals(0) || codigo.Equals(R.CODROLE)))
                         select R;
                listaRole = RL.ToList();
            }
            return listaRole;
        }






    }
}
